/**
 * ImageShow.java
 * Retrieves and resizes thumbnail image from the blobstore, returning
 * a URL for web page display.
 */
package com.example.myproject;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;

import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.files.AppEngineFile;
import com.google.appengine.api.files.FileServiceFactory;
import com.google.appengine.api.images.Image;
import com.google.appengine.api.images.ImagesService;
import com.google.appengine.api.images.ImagesServiceFactory;
import com.google.appengine.api.images.Transform;

public class ImageShow {
	
	public ImageShow(){}
	
	public String show(String fileType, Long id)
	{
			
			final String FILESYSTEM = "/blobstore/";
					
			ThumbnailUploadDAO dao = new ThumbnailUploadDAO();
			ThumbnailUploadDTO dto = new ThumbnailUploadDTO();
			
			// Find the image in the blobstore.
			dto =  dao.findById(id);

			AppEngineFile AFE = new AppEngineFile(FILESYSTEM + dto.getPath());
			BlobKey bk = FileServiceFactory.getFileService().getBlobKey(AFE);
			
			ImagesService imagesService = ImagesServiceFactory.getImagesService();
		    
		    String imageUrl = imagesService.getServingUrl(bk);

	    return  imageUrl;	

	}
	
}
